// ignore_for_file: file_names, avoid_print, no_logic_in_create_state, unused_element

import 'package:flutter/material.dart';

class MyApp3 extends StatefulWidget {
  const MyApp3({super.key});

  @override
  State<MyApp3> createState() {
    print('1_创建State');
    return _MyApp3State();
  }
}

class _MyApp3State extends State<MyApp3> {
  int _counter = 0;

  void _incrementCounter() {
    setState(() {
      _counter++;
    });
  }

  @override
  void initState() {
    super.initState();
    // 常在此处初始化一些数据
    print('2_initState');
  }

  @override
  void didChangeDependencies() {
    super.didChangeDependencies();
    // 常在此处获取外部数据（发送网络请求）
    print('3_didChangeDependencies');
  }

  @override
  void didUpdateWidget(covariant MyApp3 oldWidget) {
    super.didUpdateWidget(oldWidget);
    print('5_didUpdateWidget');
  }

  @override
  Widget build(BuildContext context) {
    print('4_build');

    @override
    void deactivate() {
      super.deactivate();
      print('7_deactivate');
    }

    @override
    void dispose() {
      super.dispose();
      print('6_dispose销毁了');
    }

    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: const Text('生命周期'),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            const Text(
              'You have pushed the button this many times:',
            ),
            Text(
              '$_counter',
              style: Theme.of(context).textTheme.headlineMedium,
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: const Icon(Icons.add),
      ), // This trailing comma makes auto-formatting nicer for build methods.
    );
  }
}
